<?php
/**
 * Created by PhpStorm.
 * User: 68008000
 * Date: 2017/11/30
 * Time: 10:35
 */

namespace app\index\controller;


use think\Controller;
use think\Session;

/**
 * Class User
 * @package app\index\controller
 * 前台用户控制器
 */
class Users extends Controller
{
    protected $db;
    public function __construct()
    {
        parent::__construct();
        $this->db = new \app\common\model\Users();
    }
    //注册
    public function register(){
        //处理title
        $conf = ['title'=>'阿里巴巴1688.com - 注册','css'=>'register','js'=>'register'];
        $this->assign('conf',$conf);
        //注册用户
        if(request()->isPost()){
            $data=input('post.');
            $res=$this->db->register($data);
            if ($res['valid']) {
                $this->success($res['msg'],'login');
            } else {
                $this->error($res['msg']);
            }
        }
        //视图
        return view();
    }
    //登录
    public function login(){
        //处理title
        $conf = ['title'=>'阿里巴巴1688.com -登录','css'=>'login','js'=>'login'];
        $this->assign('conf',$conf);
        if(request()->isPost()){
            $data=input('post.');
            $res=$this->db->login($data);
            if ($res['valid']) {
                $this->success($res['msg'],'Index\index');
            } else {
                $this->error($res['msg']);
            }
        }
        //视图
        return view();
    }
    //退出
    public function out(){
        Session::delete('index');
        $this->success('退出成功','index/users/login');
    }
}